package com.andaily.domain.dto.account;

import org.apache.commons.lang.StringUtils;

import java.util.Map;

/**
 * @author Shengzhao Li
 */
public class AccountSearchDTO {

    /**
     * Maybe it is split by -.
     * e.g.   1-100
     */
    private String amount;
    /**
     * Maybe choose one or more.
     * the value is guid
     */
    private String types;
    /**
     * If not set, the value is empty.
     */
    private String date;
    /**
     * Fuzzy matching
     */
    private String description;

    // for paging
    private int pageNumber;
    private int totalSize;

    /**
     * Default constructor
     */
    public AccountSearchDTO() {
    }

    public int getPageNumber() {
        return pageNumber;
    }

    public void setPageNumber(int pageNumber) {
        this.pageNumber = pageNumber;
    }

    public int getTotalSize() {
        return totalSize;
    }

    public void setTotalSize(int totalSize) {
        this.totalSize = totalSize;
    }

    public String getTypes() {
        return types;
    }

    public void setTypes(String types) {
        this.types = types;
    }

    public String getDate() {
        return date;
    }

    public void setDate(String date) {
        this.date = date;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getAmount() {
        return amount;
    }

    public void setAmount(String amount) {
        this.amount = amount;
    }

    public void addQueryParams(Map<String, Object> map) {
        String amountFrom = null;
        String amountTo = null;
        if (StringUtils.isNotEmpty(amount)) {
            String[] amountPeriod = amount.split("-");
            if (amountPeriod.length == 2) {
                amountFrom = amountPeriod[0];
                amountTo = amountPeriod[1];
            } else {
                amountFrom = amountPeriod[0];
                amountTo = amountPeriod[0];
            }
        }
        map.put("amountFrom", amountFrom);
        map.put("amountTo", amountTo);

        map.put("date", StringUtils.isNotEmpty(date) ? date : null);
        String[] typeArray = null;
        if (StringUtils.isNotEmpty(types)) {
            String[] strings = types.split(",");
            if (strings.length > 0) {
                typeArray = strings;
            }
        }
        map.put("typeGuids", typeArray);
        map.put("description", StringUtils.isNotEmpty(description) ? "%" + description + "%" : null);
    }
}
